package com.adv.ems.filters.original.before;

import com.adv.ems.db.entity.CollectPointDO;
import com.adv.ems.filters.EnergyDataBaseFilter;
import com.adv.ems.filters.dto.FilterParam;
import com.adv.ems.filters.original.dto.EnergyDataOriginalBeforeDTO;
import com.adv.ems.manager.CollectPointManager;
import com.adv.ems.model.vo.ResultVO;
import com.adv.ems.utils.ScriptUtil;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;

@Component
public class RealValueComputeBeforeFilter extends EnergyDataBaseFilter<EnergyDataOriginalBeforeDTO, Boolean> {
    @Resource
    CollectPointManager collectPointManager;

    @Override
    protected String getFilterName() {
        return "计算真实值";
    }

    @Override
    protected double getOrder() {
        return 1;
    }

    @Override
    protected boolean isBefore() {
        return true;
    }

    @Override
    protected String getType() {
        return EnergyDataOriginalBeforeDTO.class.getName();
    }

    @Override
    protected ResultVO<Boolean> handle(FilterParam<EnergyDataOriginalBeforeDTO> param) {
        Map<Long, CollectPointDO> pointDOMap = collectPointManager.getAllMap();
        param.getList().forEach(data -> {
            CollectPointDO point = pointDOMap.get(data.getCollectPointId());
            data.setRealValue(ScriptUtil.getProcessRealValue(data, point));
        });
        return ResultVO.success();
    }
}
